
public class Calc {

  public int add(int a, int b) {
    return checkOverUnderflow( (long)a + (long)b );
  }

  private int checkOverUnderflow(long sum) {
    if (sum > Integer.MAX_VALUE)
      throw new OverflowException();
    if (sum < Integer.MIN_VALUE)
      throw new UnderflowException();
    return (int)sum;
  }

  public int sub(int a, int b) {
    return add(a, -b);
  }

}
